package autotest0220;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;


public class FirstAutotest {
    //百度网址搜索关键词“迪丽热巴”
    public void dilirebaTest() throws InterruptedException {
        //创建驱动示例，创建会话(打开浏览器)
        ChromeDriver driver = new ChromeDriver();
        Thread.sleep(3000);
        //在浏览器输入百度网址，访问百度首页
        driver.get("http://www.baidu.com");
        Thread.sleep(3000);
        //找到百度首页输入元素，并输入关键词“迪丽热巴”
        driver.findElement(By.cssSelector("#kw")).sendKeys("迪丽热巴");
        Thread.sleep(3000);
        //找到百度首页“搜索”按钮，并点击一下
        driver.findElement(By.cssSelector("#su")).click();
        Thread.sleep(3000);
        //结束会话（关闭浏览器）
        driver.quit();
    }

    public void methodTest(){
        //遍历输出热点信息
        ChromeDriver driver = new ChromeDriver();
        driver.get("https://www.baidu.com");
        List<WebElement> eles = driver.findElements(By.className("hotsearch-item"));
        for(WebElement ele: eles){
            System.out.println(ele.getText());
        }
        driver.quit();
    }
}
